<?php

class Damages_Methods_Response_GetPermissionManagmentData extends Damages_Methods_Response {

  /**
   *
   * @var Damages_Methods_Data_Processes_ProcessType[] 
   */
  public $processesDefinitions = array();

  /**
   *
   * @var Damages_Methods_Data_Permission[] 
   */
  public $permissions = array();

  /**
   *
   * @var Damages_Methods_Data_List_Field[] 
   */
  public $fields = array();

  /**
   *
   * @var Damages_Methods_Data_List_Filter[] 
   */
  public $filters = array();

  public function setData() {
    $this->setProcessesDefinitions();
    $this->setPermissions();
    $this->setFieldsAndFilters();
  }

  private function setProcessesDefinitions() {
    $processDefinitions = DamagesProcessTypesQuery::create()
            ->useProcessTypeActionsQuery()
            ->useActionsQuery()
            ->orderByName()
            ->endUse()
            ->endUse()
            ->with('ProcessTypeActions')
            ->with('Actions')
            ->find();

    foreach ($processDefinitions as $processDefinition) {
      $this->processesDefinitions[] = new Damages_Methods_Data_Processes_ProcessType($processDefinition);
    }
  }

  public function setPermissions() {
    $permissions = DamagesPermissionsQuery::create()->find();
    foreach ($permissions as $permission) {
      $this->permissions[] = new Damages_Methods_Data_Permission($permission, false);
    }
  }

  public function setFieldsAndFilters() {
    $filters = DamagesListFiltersQuery::create()->orderByName()->find();
    foreach ($filters as $filter) {
      $this->filters[] = new Damages_Methods_Data_List_Filter($filter);
    }

    $fields = DamagesListFieldsQuery::create()->orderByName()->find();
    foreach ($fields as $field) {
      $this->fields[] = new Damages_Methods_Data_List_Field($field);
    }
  }

}